from rich.console import Console
from rich.table import Table
from rich.live import Live
import yfinance as yf
import time

console = Console()

def stock_tracker(tickers=["AAPL", "MSFT", "TSLA"]):
    with Live(auto_refresh=False) as live:
        while True:
            table = Table(title="实时股价监控")
            for ticker in tickers:
                stock = yf.Ticker(ticker)
                info = stock.info
                table.add_row(
                    ticker,
                    f"${info['currentPrice']:.2f}",
                    f"{info['regularMarketChangePercent']}%",
                    info['marketState']
                )
            live.update(table, refresh=True)
            time.sleep(60)

stock_tracker()